﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class forum_new : FBasePage
{
    // Fields

    public List<Maticsoft.Model.Category> Categorylist = new List<Maticsoft.Model.Category>();
    public List<Maticsoft.Model.Category> catelist = new List<Maticsoft.Model.Category>();

    public bool falg = false;


    // Methods
    public void AddBBs()
    {
        Maticsoft.BLL.UserInfo info = new Maticsoft.BLL.UserInfo();
        Maticsoft.BLL.UserInfo info2 = new Maticsoft.BLL.UserInfo();
        int num = Convert.ToInt32(base.Request["category"]);
        string str = base.Request["title"];
        string str2 = base.Request["content"];
        string str3 = "0";
        string str4 = info2.Getuserid(base.UserName).ToString();
        if ((((str.IndexOf("<") != -1) || (str.IndexOf(">") != -1)) || (str2.IndexOf("<") != -1)) || (str2.IndexOf(">") != -1))
        {
            this.SetError("您输入了非法参数，提交失败");
            base.Response.Redirect("new.aspx");
        }
        else
        {
            Maticsoft.BLL.topic topic = new Maticsoft.BLL.topic();
            Maticsoft.Model.topic model = new Maticsoft.Model.topic();
            model.Public_id = num;
            model.Title = str;
            model.Content = str2;
            model.Parent_id = Convert.ToInt32(str3);
            model.User_id = Convert.ToInt32(str4);
            model.Reply_number = 0;
            model.View_number = 0;
            model.create_time = DateTime.Now;
            model.Last_time = DateTime.Now;
            if (topic.Add(model) > 0)
            {
                base.Response.Redirect("topic.aspx?id=" + topic.Getbbsid(model.User_id, model.Title, model.create_time));
            }
            else
            {
                this.SetError("error");
            }
        }
    }

    public string Get_name(string ename)
    {
        Maticsoft.BLL.Category category = new Maticsoft.BLL.Category();
        return category.Get_name(this.Session["ename"].ToString());
    }

    public void GetCategory()
    {
        Maticsoft.BLL.Category category = new Maticsoft.BLL.Category();
        string ename = "";
        if (base.CurrentCity != null)
        {
            ename = base.CurrentCity.Ename;
        }
        this.Categorylist = category.GetModelList("ename='" + ename + "'");
        this.catelist = category.GetModelList("Zone='public'");
    }

    protected override void OnLoad(EventArgs e)
    {
        base.OnLoad(e);
        this.GetCategory();
        if (base.Request["ASNzY"] != null)
        {
            this.falg = true;
        }
        if (base.Request.Form["commit"] == "成立")
        {
            if (!(this.Page.User.Identity.IsAuthenticated && !(this.Page.User.Identity.Name == "")))
            {
                base.Response.Redirect("/account/Login.aspx");
            }
            else
            {
                this.AddBBs();
            }
        }
    }

}